package org.example.learn_example.vo;

import lombok.Data;

import java.util.LinkedList;

/*
* 迷宫路径定义
* */
@Data
public class MazePath<T> {

    private boolean isFinish=false;
    private LinkedList<T> linkedList = new LinkedList<T>();

    /*
     * index  是下标 不是第几个 是从0开始的  不从1开始
     *
     * */
    public boolean addElementAtIndex(T element,int index){
        final int size = linkedList.size();
        if(index>=0 && index<=size && element!=null)
        {
            linkedList.add(index,element);
            return true;
        }
        return false;
    }

    /*
    * index 是下标 不是第几个 是从0开始的  不从1开始
    *
    * */
    public boolean removeElementAtIndex(int index){
        final int size = linkedList.size();
        if(index>=0 && index<size )
        {
            linkedList.remove(index);
            return true;
        }
        return false;
    }

    public boolean appendElement(T element){
        if (element!=null) {
            linkedList.addLast(element);
            return true;
        }
        return false;
    }

    public boolean containsElement(T element){
        if (element!=null) {
            boolean j= linkedList.contains(element);
            return j;
        }
        return false;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i < linkedList.size(); i++) {
            final T t = linkedList.get(i);
            stringBuilder.append(t.toString()+" ====> ");
        }
        return stringBuilder.toString();
    }

}
